package com.studio.framework.controller.monitorSystem.controller;

import com.studio.framework.controller.monitorSystem.bean.SysUser;
import com.studio.framework.controller.monitorSystem.dto.SysUserDto;
import com.studio.framework.controller.monitorSystem.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author jujh
 * @Date 2018/7/26
 * 登录
 */
@Controller
public class LoginController {

    @Autowired
    private SysUserService sysUserService;

//    @RequestMapping(value = "/*")
//    public String login() {
//        return "login";
//    }

    @RequestMapping(value = "/login.html")
    public String loginPage() {
        return "login";
    }

    @RequestMapping(value = "/doLogin.html")
    @ResponseBody
    public String doLogin(HttpServletRequest request, SysUserDto sysUserDto) {
        SysUser sysUser = sysUserService.doLogin(sysUserDto);
        if (null != sysUser) {
            request.getSession().setAttribute("user", sysUser);
            return "ok";
        } else {
            return "用户名或密码不存在！";
        }
    }

    @RequestMapping(value = "/loginout.html")
    public String loginout(HttpServletRequest request) {
        request.getSession().setAttribute("user", null);
        return "login";
    }
}
